#include "world.h"

#include <pspdebug.h>

#define printf pspDebugScreenPrintf

world::world(const char* filename)
{
	printf("Constructor of class World!\n");
        
	if(read_map(filename) == false) printf("Unable to load file into World_Array!\n");
	else printf("world class is created!\n"); 
}

world::~world(void)
{
	if(data != NULL)
		delete[] data;
}

bool world::read_map(const char* filename)
{       
	if(filename != NULL)
	{
		FILE* file;
		file = fopen(filename, "rb");

		printf("opening file '%s'!\n", filename);
		    
		if(file == NULL) return(false);

		printf("File '%s' is open!\n", filename);

		fseek (file , 0 , SEEK_END);
		int size = ftell (file);
		rewind (file);

		data = new byte[size];

		int i=0;
		for(i = 0; i < size; i++)
		{
			fread(&data[i], sizeof(data[i]), sizeof(data[i]), file);
			printf("%c", (char)data[i]);
		}

		printf("Finished reading\n");

		fclose(file);
	}

return(true);
}

